const createError = require('http-errors');
const express = require('express');
const path = require('path');
const cookieParser = require('cookie-parser');
const logger = require('morgan');
sql = require('./plugin/sql')
tokenFun = require('./plugin/token')
commonFun = require('./plugin/commonFun')
audioFileIdList = []


const indexRouter = require('./routes/index');
const usersRouter = require('./routes/users');
const loginRouter = require('./routes/login');
const trendsRouter = require('./routes/trends');
const outLoginRouter = require('./routes/outLogin');
const markerRouter = require('./routes/marker');
const lineRouter = require('./routes/line');
const fileRouter = require('./routes/file');
const dsRouter = require('./routes/deepseek');
const activityRouter = require('./routes/activity');
baiduAI = require("./module/baiduAI/index");
const app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.use(express.static('file'))
app.set('view engine', 'jade');

app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', indexRouter);
app.use('/user', usersRouter);
app.use('/login', loginRouter);
app.use('/outLogin', outLoginRouter);
app.use('/trends', trendsRouter);
app.use('/ds', dsRouter);
app.use('/marker', markerRouter);
app.use('/line', lineRouter);
app.use('/activity', activityRouter);
app.use('/file', fileRouter);



// catch 404 and forward to error handler
app.use((req, res, next) => {
  res.header("Content-Type", "application/json;charset=utf-8");
  next(createError(404));
});

// error handler
app.use((err, req, res, next) =>{
  // set locals, only providing error in development
  res.locals.message = err.message;
  res.locals.error = req.app.get('env') === 'development' ? err : {};
  // render the error page
  res.status(err.status || 500);
  res.render('error');
});




// baiduAI.getAIData()

// console.log(markdownContent)

module.exports = app;
